<template>
  <ww-open-data v-if="isWxUser" :type="type" :openid="openid" />
  <span v-else>{{ openid }}</span>
</template>

<script>
import store from '@/store'

/**
 * 若 type=userName，此时 openid 对应 userid
若 type=departmentName，此时 openid 对应 departmentid
 */
export default {
  name: 'WxOpenData',
  props: {
    type: {
      type: [String, Number],
      default: 'userName'
    },
    openid: [String, Number]
  },
  computed: {
    isWxUser() {
      const userInfo = store.state.user.userInfo
      if (userInfo) {
        // return userInfo.isBindingWork == 2 // 是企业微信登录
        return [3, 4].includes(userInfo.loginType)// 是企业微信登录
      }
      return false
    }
  },
  mounted() {
    if (this.isWxUser && typeof WWOpenData !== 'undefined') {
      WWOpenData.bind(this.$el)
    }
  }
}
</script>
